#include "purchaseeditdialog.h"
#include "ui_purchaseeditdialog.h"

/*void PurchaseEditDialog::setEditMode(bool mode)
{
    this->flag = mode;
    qDebug()<<"<-->"<<falg;
}*/

PurchaseEditDialog::PurchaseEditDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PurchaseEditDialog)
{
    ui->setupUi(this);
}

PurchaseEditDialog::~PurchaseEditDialog()
{
    delete ui;
}

void PurchaseEditDialog::on_buttonBox_accepted()
{
    QString id = ui->lineEdit_1->text();
    QString name = ui->lineEdit_2->text();
    QString size = ui->lineEdit_3->text();
    QString color = ui->lineEdit_4->text();
    QString number = ui->lineEdit_5->text();
    QString category = ui->lineEdit_6->text();
    QString brand = ui->lineEdit_7->text();
    QString intoprice = ui->lineEdit_8->text();
    QString saleprice = ui->lineEdit_9->text();
    QString unit = ui->lineEdit_10->text();
    float sum = intoprice.toFloat()*number.toFloat();
    qDebug()<<sum;

    SqlManage conn;
    //新行添加
    conn.exec(QString("insert into goods(id, goods_name, category, brand, size, color, number, unit, into_price, sale_price, sum)"
                              "values('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10', %11)")
            .arg(id)
            .arg(name)
            .arg(category)
            .arg(brand)
            .arg(size)
            .arg(color)
            .arg(number)
            .arg(unit)
            .arg(intoprice)
            .arg(saleprice)
            .arg(sum));
    conn.closeSql();
}

void PurchaseEditDialog::on_buttonBox_clicked(QAbstractButton *button)
{
    if(ui->buttonBox->button(QDialogButtonBox::Ok) == button)
    {
        QString id = ui->lineEdit_1->text();
        QString name = ui->lineEdit_2->text();
        QString size = ui->lineEdit_3->text();
        QString color = ui->lineEdit_4->text();
        QString number = ui->lineEdit_5->text();
        QString category = ui->lineEdit_6->text();
        QString brand = ui->lineEdit_7->text();
        QString intoprice = ui->lineEdit_8->text();
        QString saleprice = ui->lineEdit_9->text();
        QString unit = ui->lineEdit_10->text();
        if(id == ""||name == "" || size == "" || color == "" || number == "" || category == "" || brand == "" || intoprice == "" || saleprice == "" || unit == "" )
        {
            QMessageBox msg(QMessageBox::Warning,tr("注意"),tr("请填好商品的相关信息！"),QMessageBox::Yes);
            msg.exec();
        }
        else
        {
            on_buttonBox_accepted();
        }
    }
    else
    {
        emit reject();
    }
}
